package main

/**
求战斗力
*/
import "fmt"

func teat() {
	soldiers := []int{5, 10, -5}
	battle(soldiers)
	soldiers = []int{8, -8}
	battle(soldiers)
	soldiers = []int{10, 2, -5, -107}
	battle(soldiers)
	soldiers = []int{1, -2, -1, 1, 2}
	battle(soldiers)
}

func battle(soldiers []int) []int {
	length := len(soldiers)
	hig := length - 1
	low := 1
	for low <= hig {
		if soldiers[low] < 0 && soldiers[low-1] > 0 {
			if -soldiers[low] == soldiers[low-1] {
				soldiers = append(soldiers[:low-1], soldiers[low+1:]...)
			} else if -soldiers[low] > soldiers[low-1] {
				soldiers = append(soldiers[:low-1], soldiers[low:]...)
			} else {
				soldiers = append(soldiers[:low], soldiers[low+1:]...)
			}
			hig = len(soldiers) - 1
			low = 1
		} else {
			low++
		}

		if hig > 1 {
			if soldiers[hig] < 0 && soldiers[hig-1] > 0 {
				if -soldiers[hig] == soldiers[hig-1] {
					soldiers = append(soldiers[:hig-1], soldiers[hig+1:]...)
				} else if -soldiers[hig] > soldiers[hig-1] {
					soldiers = append(soldiers[:hig-1], soldiers[hig:]...)
				} else {
					soldiers = append(soldiers[:hig], soldiers[hig+1:]...)
				}
				hig = len(soldiers) - 1
				low = 1
			} else {
				hig--
			}
		}
	}
	fmt.Println(soldiers)
	return soldiers
}
